const a = {};

Object.defineProperty(a, 'id', {
  value: '1',
  enumerable: true,
  // configurable: false,   // 不配置,默认为false
  // writable: false,   // 不配置，默认为false
});

a.b = 2;

console.log(a);

const descriptor = Object.getOwnPropertyDescriptor(a, 'id');
const descriptorB = Object.getOwnPropertyDescriptor(a, 'b');

console.log(descriptor);
console.log(descriptorB);

console.log('***************************************');

const foo = {
  _id: 1,
};
Object.defineProperty(foo, 'id', {
  set: function (val) {
    console.log('set id = ', val);
    this._id = val;
  },
  get: function () {
    return this._id;
  },
});

console.log(foo);
foo.id = 2;
console.log(foo.id);

console.log('***************************************');

const foo1 = {
  _id: 1,
  get id() {
    return this._id;
  },
  set id(val) {
    console.log('set id = ', val);
    this._id = val;
  }
};

console.log(foo1);
foo1.id = 2;
console.log(foo1.id);